var GraceJS = require("../../Grace.JS/grace.js");
import { apiServer } from '../../common.js';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        itShow: false,
        book_list: [],
        tutorial_list: [],
        news_list: [],
        swiperItems: [
            {
                img: 'http://pic.zhengbingdong.com/boke/banner002.png',
                url: '',
                title: "测试标题 001",
                opentype: 'click'
            },
            {
                img: 'http://pic.zhengbingdong.com/boke/banner001.png',
                url: '',
                title: "测试标题 001",
                opentype: 'click'
            },
            {
                img: 'http://pic.zhengbingdong.com/boke/banner003.png',
                url: '',
                title: "测试标题 001",
                opentype: 'click'
            },
            {
                img: 'http://pic.zhengbingdong.com/boke/banner004.png',
                url: '',
                title: "测试标题 001",
                opentype: 'click'
            }
        ],
        speakerMsgs: [
            { title: "本人接受软件开发外包，点击了解产品和服务流程", url: "/pages/serve/index", opentype: "switchTab" },
            { title: "每日分享 GitGub 推荐的星标项目", url: "/pages/git-project-list/index", opentype: "navigate" }
        ],
        menu: [
            { 'type': 'navigate', 'url': '/pages/bbs/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon2.png', 'name': '技术社区' },
            { 'type': 'switchTab', 'url': '/pages/tutorial/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon3.png', 'name': '编程教程' },
            { 'type': 'navigate', 'url': '/pages/git-project-list/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon5.png', 'name': 'Github开源' },
            { 'type': 'navigate', 'url': '/pages/book/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon6.png', 'name': '在线书籍' },
            { 'type': 'navigate', 'url': '/pages/nav-list/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon7.png', 'name': '导航收录' },
            { 'type': 'navigate', 'url': '/pages/code-list/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon8.png', 'name': '代码片段' },
            { 'type': 'switchTab', 'url': '/pages/serve/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon4.png', 'name': '我的服务' },
            { 'type': 'navigate', 'url': '/pages/index/index', 'icon': 'http://pic.zhengbingdong.com/boke/icon9.png', 'name': '关于作者' },
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getNewsList()
        this.getTutorialList()
        this.getBookList()
    },

    // 获取书籍
    getBookList: function () {
        var that = this;
        GraceJS.get(
            apiServer + 'resume.Book/getReand',
            {}, {},
            function (res) {
                if (res.code == 0) {
                    that.setData({
                        book_list: res.data,
                    })
                } else {
                    GraceJS.msg(res.message)
                }
            }
        )
    },

    // 获取教程
    getTutorialList: function () {
        var that = this;
        GraceJS.get(
            apiServer + 'resume.Tutorial/reandsTutorial',
            {}, {},
            function (res) {
                if (res.code == 0) {
                    that.setData({
                        tutorial_list: res.data,
                    })
                } else {
                    GraceJS.msg(res.message)
                }
            }
        )
    },

    // 获取技术文章
    getNewsList: function () {
        var that = this;
        GraceJS.get(
            apiServer + 'resume.boke/reands',
            {}, {},
            function (res) {
                if (res.code == 0) {
                    that.setData({
                        news_list: res.data,
                    })
                } else {
                    GraceJS.msg(res.message)
                }
            }
        )
    },

    /**
    * 用户点击右上角分享
    */
    onShareAppMessage: function () {
        return {
            title: '程序员学习园地，收录全网最全的资料，一起学习，一起成为大神',
            path: '/pages/home/index',
        }
    }
})